//
// file : ring_buf.h
// date : 4/4/05
//
#ifndef RING_BUF_H_
#define RING_BUF_H_

typedef unsigned short u16_t;
typedef unsigned char  u8_t;
typedef unsigned long  u32_t;

/***************************************************************************
**                                                                        **
** ring buffer                                                            **
**                                                                        **
** for no-lock messages read/write                                        **
**                                                                        **
***************************************************************************/

typedef struct msg_t {

    u16_t  len;  /* message length excluding message header */

    u16_t  mid;  /* message id */

}  msg_t;


/*
** initially wpnt == rpnt == 0
** if wpnt < rpnt, buffer has wrapped around the end
*/
typedef struct ring_t {

    long   wpos;      /* write position as offset to 'start' */

    long   rpos;      /* read position as offset to 'start' */

    long   end;       /* ring length as offset to 'start' */

    u8_t   start[0];  /* variable length array */

}  ring_t;


/*
** read message from msgring
*/
long  rb_read(ring_t *rb, msg_t *msg);

/*
** write message to msgring
*/
long  rb_write(ring_t *rb, msg_t *msg);

/*
**  remove message from head
*/
long rb_yank(ring_t *rb);


////////////////////////////////////////////////////////////////////////////
#endif // RING_BUF_H_
